import cx_Oracle
import requests
import json
from requests_toolbelt.multipart.encoder import MultipartEncoder

import login

def get_user_application(userInfo):
    '''
    获取首页信息中的下单列表
    '''
    url = 'http://220.171.97.55:6691' + '/api/SysUser/GetUserApplication'
    headers = {
        'Content-Type': 'application/json',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
    }
    payload = {
        'FUserID': userInfo['FUserID'],
        'FApplicationID': login.APPLICATION_ID,
        'FAppTypeID': '3',
        'FTraderID': userInfo['FTraderID'],
    }

    res = requests.post(url, headers=headers, data=json.dumps(payload))
    res.raise_for_status()
    # print(f"\t(调试)获取的首页信息：{res.json()}\t")
    data = res.json()
    if data.get('IsSuccess'):
        print(f"\t(调试)获取首页信息成功！\t")
        sale_contract_goods = data.get('Data').get('SaleContractGoods',[])
        return True,'获取首页信息成功！',sale_contract_goods
    else:
        print(f"\t(错误)获取首页信息失败：{res.text}\t")
        return False,f'获取首页信息失败：{res.text}',[]

def handleFunction(order_list):
    '''
    传入下单列表，返回匹配的某一下单具体信息，返回整个对象
    :param order_list:
    :return:
    '''
    # 测试 吐鲁番天山
    compy_info = {
			'FMaterielID': 11,
			'FPackingID': 1,
			'FFactoryID': 41,
			'FSaleAreaID': -1,
			'FGoodsPathApp': None,
			'FBillID': 1001726380,
			'FContractNumber': '202505226258',
			'FContractName': '吐鲁番天山与中铁物资集团有限公司签订的水泥特殊销售合同',
			'FCustomerID': 1006418580,
			'FSignDate': '2025-05-26T00:00:00',
			'FMaterielName': '42.5普通硅酸盐水泥 ',
			'FPacking': '散装',
			'FFactoryName': '吐鲁番天山水泥有限责任公司',
			'FCurrentPrice': 350.0,
			'FCustomerName': '中铁物资集团有限公司【G30连霍高速哈密至吐峪沟段改扩建项目】',
			'FEmployeeID': 8866,
			'FEmployeeName': '陈旭东',
			'FSaleArea': '',
			'FCnName': '天山牌',
			'FTransport': '汽车运输',
			'FProjectID': 1000149080,
			'FProjectCode': '1000149080',
			'FProjectName': 'G30连霍高速哈密至吐峪沟段改扩建项目'
		}
    return compy_info

def get_new_model(compy_info):
    '''
    获取订单模板信息
    :return:
    '''
    try:
        url = 'http://220.171.97.55:6691' + '/api/T_SaleConsignPlanBill/GetNewModel'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        payload = {
            "FBillID": compy_info['FBillID'],
        }
        res = requests.post(url, headers=headers,json=payload)
        res.raise_for_status()
        # print(f"\t(调试)订单模板信息：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            new_model_info = data.get('Data')
            print(f"\t(调试)获取订单模板信息成功：{new_model_info}\t")
            return True,new_model_info
        else:
            print(f"\t（错误）获取订单模板信息失败：{res.text}\t")
            return False,{}
    except requests.RequestException as e:
        print(f"\t（错误）获取订单模板信息接口异常：{e}\t")
        return False,{}
    except Exception as e:
        print(f"\t（错误）获取订单模板信息错误：{e}\t")
        return False,{}

def get_payment_type(compy_info):
    '''
    获取支付类型
    :return:
    '''
    try:
        f_bill_id = compy_info['FBillID']
        url = 'http://220.171.97.55:6691' + '/api/SaleBDCapitalType/QueryList'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        payload = {
            'FBillID': f_bill_id
        }
        res = requests.post(url, headers=headers,json=payload)
        res.raise_for_status()
        # print(f"\t(调试)获取支付类型：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            payment_type_list = data.get('Data')
            print(f"\t(调试)获取支付类型成功：{payment_type_list}\t")
            return True,payment_type_list
        else:
            print(f"\t（错误）获取支付类型失败：{res.text}\t")
            return False,[]
    except requests.RequestException as e:
        print(f"\t（错误）获取支付类型接口异常：{e}\t")
        return False,[]
    except Exception as e:
        print(f"\t（错误）获取支付类型错误：{e}\t")
        return False,[]

def get_pick_up_customer(compy_info,user_info):
    '''
    获取提货客户和提货方式
    :return:
    '''
    try:
        url = 'http://220.171.97.55:6691' + '/api/SaleContractGoods/QueryMatterContractListForUserNew'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        payload = {
            "FUserID": user_info['FUserID'],
            "FMaterielID": compy_info['FMaterielID'],
            "FPackingID": compy_info['FPackingID'],
            "FFactoryID": compy_info['FFactoryID'],
            "FCustomerID": compy_info['FCustomerID'],
            "FCurrentPrice": compy_info['FCurrentPrice'],
            "FEmployeeID": compy_info['FEmployeeID'],
            "FProjectID": compy_info['FProjectID'],
            "FSaleAreaID": compy_info['FSaleAreaID'],
        }
        res = requests.post(url, headers=headers,json=payload)
        res.raise_for_status()
        # print(f"\t(调试)提货客户：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            pick_up_list = data.get('Data')
            print(f"\t(调试)获取提货客户成功：{pick_up_list}\t")
            return True,pick_up_list[0]
        else:
            print(f"\t（错误）获取提货客户失败：{res.text}\t")
            return False,{}
    except requests.RequestException as e:
        print(f"\t（错误）获取提货客户接口异常：{e}\t")
        return False,{}
    except Exception as e:
        print(f"\t（错误）获取提货客户错误：{e}\t")
        return False,{}

def get_terminal_classification():
    '''
    获取终端分类
    :return:
    '''
    try:
        url = 'http://220.171.97.55:6691' + '/api/SaleBDPOSType/QuerySaleBDPOSTypeList'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        payload = {}
        res = requests.post(url, headers=headers,json=payload)
        res.raise_for_status()
        # print(f"\t(调试)获取终端分类：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            terminal_classification_list = data.get('Data')
            print(f"\t(调试)获取终端分类成功：{terminal_classification_list}\t")
            # 返回终端分类的第一项 基础设施
            return True,terminal_classification_list[0]
        else:
            print(f"\t（错误）获取终端分类失败：{res.text}\t")
            return False,{}
    except requests.RequestException as e:
        print(f"\t（错误）获取终端分类接口异常：{e}\t")
        return False,{}
    except Exception as e:
        print(f"\t（错误）获取终端分类错误：{e}\t")
        return False,{}

def read_unconfirmed_voucher():
    '''
    拉取未确认采购订单
    :return:
    '''
    try:
        url = f"{login.DVC_ADDRESS}/api/v2/voucher/readUnConfirmedVoucher"
        payload = {
            'vtCode': login.CANCEL_PURCHASE_ORDER,
            'voucherCount': '10',  # 最多10条凭证。
            'owner': login.OWNER
        }
        headers = {
            'User-Agent': 'MyApp/0.0.1',
            'appId': login.APPID,
        }
        encoder = MultipartEncoder(fields=payload)
        headers['Content-Type'] = encoder.content_type
        res = requests.post(url, headers=headers, data=encoder)
        res.raise_for_status()
        print(f"\t(调试)拉取的未确认订单：{res.json()}\t")
    except requests.RequestException as e:
        print(f"\t（错误）调用拉取未确认凭证接口异常：{e}\t")
        return []
    except Exception as e:
        print(f"\t（错误）拉取未确认凭证错误：{e}\t")
        return []

def get_receive_address(compy_info,user_info,pick_up_customer):
    '''
    查询收货地址
    :return:
    '''
    try:
        url = 'http://220.171.97.55:6691' + '/api/SaleContractAddress/QueryContractAddressForUserNew'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        payload = {
            "FUserID": user_info['FUserID'],
            "FTransportID": pick_up_customer['FTransportID'],
            "FDeliveryID": pick_up_customer['FDeliveryID'],
            "FCustomerID": compy_info['FCustomerID'],
            "FPackingID": compy_info['FPackingID'],
            "FBillID": compy_info['FBillID'],
        }
        res = requests.post(url, headers=headers,json=payload)
        res.raise_for_status()
        # print(f"\t(调试)获取收货地址：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            receive_address_list = data.get('Data')
            print(f"\t(调试)获取收货地址成功：{receive_address_list}\t")
            # 加一个筛选，返回符合条件的地址，没有的话新增收货地址，测试 目前返回第一个
            return True,receive_address_list[0]
        else:
            print(f"\t（错误）获取收货地址失败：{res.text}\t")
            return False,{}
    except requests.RequestException as e:
        print(f"\t（错误）获取收货地址接口异常：{e}\t")
        return False,{}
    except Exception as e:
        print(f"\t（错误）获取收货地址错误：{e}\t")
        return False,{}

def submit_order(user_info,compy_info,new_model_info,payment_type,payment_index,terminal_classification,pick_up_customer,receive_address):
    '''
    提交订单
    :return:
    '''
    try:
        url ='http://220.171.97.55:6691' + '/api/SaleConsignPlanBill/InsertNewConsignPlanBill'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        params = {
                "FBillID": new_model_info['FBillID'],
                "FBillCode": new_model_info['FBillCode'],
                "FBillTypeID": 150,  # 暂未找到
                "FCompanyID": new_model_info['FCompanyID'],
                "FAccountCompID": new_model_info['FAccountCompID'],
                "FFactoryID": compy_info['FFactoryID'],
                "FDepartmentID": new_model_info['FDepartmentID'],
                "FSaleManID": new_model_info['FSaleManID'],
                "FCustomerID": new_model_info['FCustomerID'],
                "FConsignCustomerID": pick_up_customer['FConsignCustomerID'],
                "FConsignName": pick_up_customer['FConsignName'],
                "FContractDetailID": pick_up_customer['FContractDetailID'],
                "FTContractDetailID": new_model_info['FTContractDetailID'],
                "FBeginDate": new_model_info['FBeginDate'], # 开始日期 待修改
                "FEndDate": new_model_info['FEndDate'], # 结束日期 待修改
                "FMaterielID": pick_up_customer['FMaterielID'],
                "FPackingID": pick_up_customer['FPackingID'],
                "FTransportID": pick_up_customer['FTransportID'],
                "FPriceModeID": new_model_info['FPriceModeID'],
                "FDeliveryID": pick_up_customer['FDeliveryID'],
                "FCarrierID": new_model_info['FCarrierID'],
                "FShipSign": new_model_info['FShipSign'],
                "FTransportation": new_model_info['FTransportation'],
                "FLinkTel": new_model_info['FLinkTel'],
                "FPlanAmount": 1,  # 下单数量 多少吨
                "FScheVanAmount": new_model_info['FScheVanAmount'],
                "FBillAmount": new_model_info['FBillAmount'],
                "FPickupAmount": new_model_info['FPickupAmount'],
                "FGoodsPrice": new_model_info['FGoodsPrice'],
                "FCGoodsprice": new_model_info['FCGoodsprice'],
                "FAGoodsPrice": new_model_info['FAGoodsPrice'],
                "FRGoodsPrice": new_model_info['FRGoodsPrice'],
                "FCFreightPrice": new_model_info['FCFreightPrice'],
                "FTFreightPrice": new_model_info['FTFreightPrice'],
                "FMidWayPrice": new_model_info['FMidWayPrice'],
                "FUnloadPrice": new_model_info['FUnloadPrice'],
                "FGoodsMoney": new_model_info['FGoodsMoney'],
                "FCFreightMoney": new_model_info['FCFreightMoney'],
                "FTFreightMoney": new_model_info['FTFreightMoney'],
                "FMidWayMoney": new_model_info['FMidWayMoney'],
                "FUnloadMoney": new_model_info['FUnloadMoney'],
                "FDeliveryMoney": new_model_info['FDeliveryMoney'],
                "FPlanMoney": new_model_info['FPlanMoney'],
                "FLoadingSiteID": new_model_info['FLoadingSiteID'],
                "FPosName": new_model_info['FPosName'],
                "FTAreaID": new_model_info['FTAreaID'],
                "FAddressID": receive_address['FAddressID'],
                "FDeliveryAddress": receive_address['FDeliveryAddress'],
                "FMidWayID": new_model_info['FMidWayID'],
                "FGatheringBillID": new_model_info['FGatheringBillID'],
                "FGatheringBillNumber": new_model_info['FGatheringBillNumber'],
                "FOldNumber": new_model_info['FOldNumber'],
                "FExecStatus": new_model_info['FExecStatus'],
                "FRemark": receive_address['FDeliveryAddress'],  # 备注 地址?
                "FPlying": new_model_info['FPlying'],
                "FCreator": user_info['FUserName'],
                "FCreateTime": new_model_info['FCreateTime'],
                "FMender": new_model_info.get('FMender') or (user_info.get('FUserName') if user_info.get('FUserName') else ''),
                "FModifyTime": new_model_info['FModifyTime'],
                "FStatus": new_model_info['FStatus'],
                "FAuditingSign": new_model_info['FAuditingSign'],
                "FAssessor": new_model_info['FAssessor'],
                "FAuditingTime": new_model_info['FAuditingTime'],
                "FSourceBillID": new_model_info['FSourceBillID'],
                "FSourceType": new_model_info['FSourceType'],
                "FSourceBillTypeID": new_model_info['FSourceBillTypeID'],
                "FSaleOrgID": new_model_info['FSaleOrgID'],
                "FSaleTypeID": new_model_info['FSaleTypeID'],
                "FUnitID": new_model_info['FUnitID'],
                "FCapitalTypeID": payment_type[payment_index]['FCapitalTypeID'], # 支付类型 选择方式待修改 10/20
                "FContractASID": new_model_info['FContractASID'],
                "FContractID": compy_info['FBillID'],
                "FVer": terminal_classification['FVer'],
                "FRowVersion": new_model_info['FRowVersion'],
                "FRDeliveryMoney": new_model_info['FRDeliveryMoney'],
                "FRPlanMoney": new_model_info['FRPlanMoney'],
                "FRecLoadingSiteID": new_model_info['FRecLoadingSiteID'],
                "FDepotID": new_model_info['FDepotID'],
                "FGoodsClassID": new_model_info['FGoodsClassID'],
                "FPOSTypeID": new_model_info['FPOSTypeID'],
                "FTraderMarkID": new_model_info['FTraderMarkID'],
                "FSaleCateID": new_model_info['FSaleCateID'],
                "FTaxRate": new_model_info['FTaxRate'],
                "FIsOverLoad": 1,  # 允许超重 0---不允许 1---允许
                "FContractCode": new_model_info['FContractCode'],
                "FContractNumber": new_model_info['FContractNumber'],
                "FSaleChannelID": new_model_info['FSaleChannelID'],
                "FBusinessSegmentID": new_model_info['FBusinessSegmentID'],
                "FProjectID": new_model_info['FProjectID'],
                "FProjectName": new_model_info['FProjectName'],
                "FMethodID": new_model_info['FMethodID'],
                "FContGoodsPrice": new_model_info['FContGoodsPrice'],
                "FFTaxRate": new_model_info['FFTaxRate'],
                "RowState": new_model_info['RowState'],
                "FCapitalTypeName": payment_type[payment_index]['FCapitalTypeName']  # 现金/承兑
            }
        payload = {
            "Entity":json.dumps(params)
        }
        print(f"\t(调试)提交订单入参:{payload}\t")
        # return
        res = requests.post(url, headers=headers, json=payload)
        res.raise_for_status()
        print(f"\t(调试)提交订单返回：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            if payment_index == 0:
                type = '现金'
            else:
                type = '承兑'
            print(f"\t(调试)下单成功!（支付方式：{type}）\t")
            return True
        else:
            error_msg = data.get('Message')
            if '余额不足' in error_msg:
                if payment_index == 0 and len(payment_type) > 0:
                    print(f'\t(调试)尝试切换为承兑支付...\t')
                    return submit_order(user_info,compy_info,new_model_info,payment_type,1,terminal_classification,pick_up_customer,receive_address)
                else:
                    print('\t(调试)资金余额不足，下单失败\t')
                    return False
            else:
                print(f"\t（错误）提交订单失败：{res.text}\t")
                return False
    except requests.RequestException as e:
        print(f"\t（错误）提交订单接口异常：{e}\t")
        return False
    except Exception as e:
        print(f"\t（错误）提交订单错误：{e}\t")
        return False

def get_sale_order(user_info):
    '''
    获取销售订单列表，第一项就是刚刚下的销售订单
    :return:
    '''
    try:
        url = 'http://220.171.97.55:6691' + '/api/SaleConsignPlanBill/QuerySalePlanBillList'
        headers = {
            'Content-Type': 'application/json',
            'User-Agent': 'Mozilla/5.0 (Linux; Android 12; HBN-AL00 Build/HUAWEIHBN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/114.0.5735.196 Mobile Safari/537.36 uni-app Html5Plus/1.0 (Immersed/41.185184)'
        }
        payload = {
            "FSearchText": "",
	        "FUserID": user_info['FUserID'],
            "FType": "1",
            "FPageIndex": "1",
            "FPageSize": "5"
        }
        res = requests.post(url, headers=headers,json=payload)
        res.raise_for_status()
        # print(f"\t(调试)获取销售订单列表：{res.json()}\t")
        data = res.json()
        if data.get('IsSuccess'):
            sale_order_list = data.get('Data')
            print(f"\t(调试)获取销售订单列表成功：{sale_order_list}\t")
            return True,sale_order_list[0]
        else:
            print(f"\t（错误）获取销售订单列表失败：{res.text}\t")
            return False,{}
    except requests.RequestException as e:
        print(f"\t（错误）获取销售订单列表接口异常：{e}\t")
        return False,{}
    except Exception as e:
        print(f"\t（错误）获取销售订单列表错误：{e}\t")
        return False,{}


def assemble_sale_order_message():
    '''
    组装销售订单报文
    :return:
    '''
    print('在此组装销售订单报文')

def save_receive_voucher():
    '''
    存表
    :return:
    '''
    try:
        # 确保 Oracle Instant Client 已初始化
        if not hasattr(cx_Oracle, '_client_initialized') or not cx_Oracle._client_initialized:
            cx_Oracle.init_oracle_client(lib_dir=login.ORACLE_PATH)
            cx_Oracle._client_initialized = True
        # 创建 DSN 连接字符串
        dsn = cx_Oracle.makedsn(login.ORACLE_IP, login.PORT, service_name=login.SERVICE_NAME)
        # 建立连接
        connection = cx_Oracle.connect(user=login.USER, password=login.PASSWORD, dsn=dsn)

        # 创建游标
        cursor = connection.cursor()


    finally:
        # 关闭游标和连接
        if 'cursor' in locals():
            cursor.close()
        if 'connection' in locals():
            connection.close()

def save_send_voucher():
    '''
    存表
    :return:
    '''
    order_no = ''
    try:
        # 确保 Oracle Instant Client 已初始化
        if not hasattr(cx_Oracle, '_client_initialized') or not cx_Oracle._client_initialized:
            cx_Oracle.init_oracle_client(lib_dir=login.ORACLE_PATH)
            cx_Oracle._client_initialized = True
        # 创建 DSN 连接字符串
        dsn = cx_Oracle.makedsn(login.ORACLE_IP, login.PORT, service_name=login.SERVICE_NAME)
        # 建立连接
        connection = cx_Oracle.connect(user=login.USER, password=login.PASSWORD, dsn=dsn)

        # 创建游标
        cursor = connection.cursor()

        cursor.execute("SELECT * FROM SUPPLIER_SENDVOUCHER WHERE ORDERNO = :1 AND VTCODE = :2 AND USCICODE = :3",(order_no,login.SALES_ORDER,login.PRIVATE_USCICODE))


    finally:
        # 关闭游标和连接
        if 'cursor' in locals():
            cursor.close()
        if 'connection' in locals():
            connection.close()

def main():
    login_result = login.main()
    if not login_result[0]:
        print(f"\t(错误)登陆失败：{login_result[1]}\t")
        return

    check_user_result = login.get_user_info()
    if not check_user_result[0]:
        print(f"\t(错误){check_user_result[1]}\t")
        return

    user_info = check_user_result[2]
    print(f"\t(调试)用户信息：{user_info}\t")

    # # 查销售订单
    # get_sale_order(user_info)
    # return
    order_list = get_user_application(user_info)
    if not order_list[0]:
        print(order_list[1])
        return

    # 公司信息
    compy_info = handleFunction(order_list[2])
    # 新订单模板信息
    new_model_info = get_new_model(compy_info)
    if not new_model_info[0]:
        print(f"\t(错误)获取新订单模板信息失败\t")
        return
    # 支付类型
    payment_type = get_payment_type(compy_info)
    if not payment_type[0]:
        print(f"\t(错误)获取支付类型失败\t")
        return
    # 终端分类
    terminal_classification = get_terminal_classification()
    if not terminal_classification[0]:
        print(f"\t(错误)获取终端分类失败\t")
        return
    # 提货客户 提货方式
    pick_up_customer = get_pick_up_customer(compy_info, user_info)
    if not pick_up_customer[0]:
        print(f"\t(错误)获取提货客户和提货方式失败\t")
        return
    # 收货地址
    receive_address = get_receive_address(compy_info, user_info, pick_up_customer[1])
    if not receive_address[0]:
        print(f"\t(错误)获取收货地址失败\t")
        return
    # 提交订单
    submit_order_status = submit_order(user_info, compy_info,new_model_info[1], payment_type[1],0, terminal_classification[1], pick_up_customer[1],
                 receive_address[1])
    if not submit_order_status:
        print(f"\t(错误)提交订单失败\t")
        return
    # 查销售订单
    return
    sale_order_detail = get_sale_order(user_info)
    if not sale_order_detail[0]:
        print(f"\t(错误)获取销售订单失败\t")
        return
    # 存销售订单
    save_send_voucher()
    # 确认签收、创建销售订单凭证成功，修改状态为1 和确认签收失败、修改状态为2
if __name__ == '__main__':
    main()

    # 拉取未确认采购订单
    # read_unconfirmed_voucher()

